/*
Write the code to find lexicographic minimum in a circular array, e.g. for the array
BCABDADAB, the lexicographic mininum is ABBCABDAD
*/

#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <fstream>
#include <set>

using namespace std;

string minArray(const string &str)
{
    vector<string> vec;
    string tmp = str + str;
    for (int i = 0; i < str.size(); i++) {
        vec.push_back(tmp.substr(i, str.size()));
    }
    sort(vec.begin(), vec.end());
    return vec[0];
}


int main(int argc, char **argv)
{
    string str = "BCABDADAB";
    cout << minArray(str) << endl;
}
